package day15;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
class FileTest {
    public static void main(String[] args)throws IOException {
        String filePath = "C:\\Users\\86152\\Desktop\\excise\\盐师22Git仓库\\day15\\abc.txt";
        File abc = new File(filePath);
        String dirPath = "C:\\Users\\86152\\Desktop\\excise\\盐师22Git仓库\\day15\\dir";
        File dir = new File(dirPath);
        // 获取绝对路径
        String absolutePath = abc.getAbsolutePath();
        System.out.println("AbsolutePath:"+absolutePath);
        // 获取构造路径
        String path = abc.getPath();
        System.out.println("Path:"+path);
        // 获取文件长度
        System.out.println("文件长度"+abc.length());
        System.out.println("目录长度"+dir.length());
        System.out.println("目录大小"+Files.size(Paths.get(dirPath)));
        File[] files = dir.listFiles();
        int count = 0;
        for(File file:files){
            if(file.isFile()){
                String fileName = file.getName();
                if(fileName.endsWith(".txt")||fileName.endsWith(".java")){
                    System.out.println(file.getAbsolutePath());
                    count += file.length();
                }
            }
        }
        System.out.println(count);
    }
    
}